// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   BuilderController.java

package com.hfstu.ifs.web;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hfstu.framework.common.tree.ITreeService;
import com.hfstu.framework.core.utils.web.Servlets;
import com.hfstu.framework.core.utils.web.springmvc.SpringmvcUtils;
import com.hfstu.ifs.dataaccess.service.*;
import com.hfstu.ifs.dataaccess.service.tree.TreeNavigationTree;
import com.hfstu.ifs.dto.*;
import com.hfstu.ifs.model.FuncDef;
import com.hfstu.ifs.model.ListNavigation;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.servlet.ModelAndView;

public class BuilderController
{

	private Logger log;
	private IMenuService menuService;
	private INodeSystemService nodeSystemService;
	private IFuncDefService funcDefService;
	private ITreeService treeService;
	private IListNavigationService listNavigationService;

	public BuilderController()
	{
		log = LoggerFactory.getLogger(com/hfstu/ifs/web/BuilderController);
	}

	public ModelAndView loadNodeSystem(HttpServletRequest request, HttpServletResponse response)
		throws IOException
	{
		String nodeSystemCode = SpringmvcUtils.getParameter("nodeSystemCode");
		NodeSystemDTO nodeSytem = nodeSystemService.getNodeSystemMenuByNodeSystemCode(nodeSystemCode);
		String json = nodeSytem.toJson();
		if (log.isInfoEnabled())
			log.info(nodeSytem.toJson());
		Servlets.writeJson(response, json);
		return null;
	}

	public ModelAndView loadFuncDefMenu(HttpServletRequest request, HttpServletResponse response)
		throws IOException
	{
		String funcDefId = SpringmvcUtils.getParameter("funcDefId");
		FuncDef funcDef = (FuncDef)funcDefService.getById(funcDefId);
		String json = (new FuncDefDTO()).transfer(funcDef).toJson();
		if (log.isInfoEnabled())
			log.info(json);
		Servlets.writeJson(response, json);
		return null;
	}

	public ModelAndView loadFuncDefNav(HttpServletRequest request, HttpServletResponse response)
		throws IOException
	{
		String funcDefId = SpringmvcUtils.getParameter("funcDefId");
		FuncDef funcDef = (FuncDef)funcDefService.getById(funcDefId);
		String json = (new FuncDefDTO()).transfer(funcDef).toJson();
		if (log.isInfoEnabled())
			log.info(json);
		Servlets.writeJson(response, json);
		return null;
	}

	public ModelAndView loadTreeNavigation(HttpServletRequest request, HttpServletResponse response)
		throws IOException
	{
		String menuId = SpringmvcUtils.getParameter("menuId");
		String navControlId = SpringmvcUtils.getParameter("navControlId");
		Map queryMap = Maps.newHashMap();
		queryMap.put("menuId", menuId);
		queryMap.put("navControlId", navControlId);
		TreeNavigationTree tnt = TreeNavigationTree.getInstance();
		tnt.reloadTreeNavigationTree(queryMap);
		String json = treeService.generateJsonCheckboxTree(tnt, Boolean.valueOf(false));
		if (log.isInfoEnabled())
			log.info(json);
		Servlets.writeJson(response, json);
		return null;
	}

	public List loadListNavigation(HttpServletRequest request, HttpServletResponse response)
		throws IOException
	{
		String menuId = SpringmvcUtils.getParameter("menuId");
		String navControlId = SpringmvcUtils.getParameter("navControlId");
		Map queryMap = Maps.newHashMap();
		queryMap.put("menuId", menuId);
		queryMap.put("listNavigation.navControl.id", navControlId);
		Map sortMap = Maps.newHashMap();
		queryMap.put("orderIndex", "ASC");
		List listNavigations = listNavigationService.findListByCondition(queryMap, sortMap);
		List listNavigationDTOs = Lists.newArrayList();
		ListNavigation listNavigation;
		for (Iterator iterator = listNavigations.iterator(); iterator.hasNext(); listNavigationDTOs.add((new ListNavigationDTO()).transfer(listNavigation)))
			listNavigation = (ListNavigation)iterator.next();

		return listNavigationDTOs;
	}

	public void initBinder(WebDataBinder binder)
	{
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(true);
		binder.registerCustomEditor(java/util/Date, new CustomDateEditor(dateFormat, true));
	}

	public IListNavigationService getListNavigationService()
	{
		return listNavigationService;
	}

	public void setListNavigationService(IListNavigationService listNavigationService)
	{
		this.listNavigationService = listNavigationService;
	}

	public ITreeService getTreeService()
	{
		return treeService;
	}

	public void setTreeService(ITreeService treeService)
	{
		this.treeService = treeService;
	}

	public IMenuService getMenuService()
	{
		return menuService;
	}

	public void setMenuService(IMenuService menuService)
	{
		this.menuService = menuService;
	}

	public INodeSystemService getNodeSystemService()
	{
		return nodeSystemService;
	}

	public void setNodeSystemService(INodeSystemService nodeSystemService)
	{
		this.nodeSystemService = nodeSystemService;
	}

	public IFuncDefService getFuncDefService()
	{
		return funcDefService;
	}

	public void setFuncDefService(IFuncDefService funcDefService)
	{
		this.funcDefService = funcDefService;
	}
}
